#include<bits/stdc++.h>
#define int long long 
using namespace std;
const int N=3e4+10;
unordered_map<int,int>vis;
int T,x,n,top=0;
set<int> S;
int solve(){
	int res=0;
	cin>>x;
	if(vis[x])S.erase(x);
	else S.insert(x);
	auto be=S.begin();
	auto ed=S.end();--ed;
	n+=(vis[x]?-1:1);
	vis[x]^=1;top=0;
	for(int i=1,r=0,lval=0,rval=0;i<n;++i){
		lval+=*be;++be;
		rval+=*ed;--ed;
		res+=(rval-max(r,lval));
		r=max(r,rval);
	}
	return res;
}
signed main(){
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>T;while(T--)cout<<solve()<<'\n';
	return 0;
}
